<template>
	<view>
		 <picker @change="bindPickerChange"  :range="array">
		                      
		 </picker>
		 <!-- #ifdef MP -->
		 <div v-if="index1==0" v-for="(value,index1) in databen" :key="value.name" @tap="dingyue(value,index1)" class="list">
		 	
		 	
		 	                   <div class="list_name">{{value.name}}</div>
		 	                   <div class="list_value">{{value.value}}</div>
		 	                   <div class="list_icon">{{icons.dayuhao}}</div>  
		 	
		 </div>
		 <!-- #endif -->
		 <!-- #ifdef APP-PLUS -->
		 <div v-if="index2==0" v-for="(value,index2) in databen" :key="value.name"  class="list">
		 	
		 	
		 	                   <div class="list_name">{{value.name}}</div>
		 	                   <div class="list_value">{{value.value}}</div>
		 	                   <div class="list_icon" @tap="dingyue(value,index2)"><u-switch :size="40" @change="dingyue(value,index2)" v-model="value.url" :active-color="icons.color" ></u-switch></div>  
		 	
		 </div>
		 <!-- #endif -->
		 <picker  @change="bindPickerChange" :value="indexarr" :range="array">
		<div v-if="index3==1" v-for="(value,index3) in databen" :key="index3" @tap="dingyue(value,index3)" class="list">
			
			
			                   <div class="list_name">{{value.name}}</div>
			                   <div class="list_value">{{array[indexarr]}}</div>
			                   <div class="list_icon">{{icons.dayuhao}}</div>  
			
		</div>
		</picker>
		<div @tap="urlfun(value.url)" v-for="(value,index4) in data" :key="index4" class="list">
			<div class="list_name">{{value.name}}</div>
			<div class="list_value">{{value.value}}</div>
			<div class="list_icon">{{icons.dayuhao}}</div>
		</div>
		<!-- #ifndef MP -->
		<div class="getup" @tap="getupfun">退出登录</div>
		<!-- #endif -->
	</view>
</template>

<script>
	var _self;
	//#ifdef APP-PLUS
	import push from "../../common/push.js";
	import permision from "../../pagesC/common/permission.js";//app判断权限
	//#endif
	export default {
		data() {
			return {
				array: ['不提醒', '震动', '声音', '震动+声音'],
				indexarr: uni.getStorageSync('sound'),
				icon:'',
				icons:'',
				version:'',
				databen:[
					// #ifdef MP
					{
					name:'消息推送设置',
					value:'', 
					url:'',
					},
					//#endif
					// #ifdef APP-PLUS
					{
					name:'消息推送通知',
					value:'',
					url:false,
					},
					//#endif
					{
					name:'聊天提醒方式',
					value:'声音+震动',
					url:'',
				}],
				data:[{
					name:'关于聚优先',
					value:'',
					url:'',
				}],
			}
		},
		onLoad() {
			_self=this;
			this.icon=uni.getStorageSync('icon');
			this.icons=uni.getStorageSync('icons');
			//#ifdef APP-PLUS
		     this.data[this.data.length-1].value='版本'+plus.runtime.version;
		//#endif
		},
		onShow() {
			//#ifdef APP-PLUS
			 this.databen[0].url=push.isOn();
			//#endif
		},
		onHide() {
			this.databen[0].url=false;
		},
		methods: {
			dingyue:function(value,id){
				if(id==0){
				//#ifdef MP
				// 获取用户的当前设置，判断是否点击了“总是保持以上，不在询问”
				uni.getSetting({
				 	// withSubscriptions: true,//是否获取用户订阅消息的订阅状态，默认false不返回
				   success(res){
				   if(res.authSetting['scope.subscribeMessage']){
				     uni.openSetting({ // 打开设置页
				       success(res) {
				       console.log(res.authSetting)
				                                }
				     });
				   }else{// 用户没有点击“总是保持以上，不再询问”则每次都会调起订阅消息
				     uni.requestSubscribeMessage({
				       tmplIds: ['6O8z0hl9dTdE1kMNk_ciPvgkqxrZAwZLarncG0FSdw0','DojvY1w7iURyVviQ4hvQ9k1snVTxGJ3-FsBnvAIAfk8','hS1RPT_7wDAax_k15HwhA1h0GyQAzXI-YXmvkRcRgPE'], // 此处可填写多个模板 ID，但低版本微信不兼容只能授权一个
				       
				       success (res) {
				         console.log(res)
				         if(res['字段'] == "accept"){// 字段就是tmplIds模板id
				             // ....
				         }
				       }
				      })
				     }
				   }
				})
				//#endif
				//#ifdef APP-PLUS
					permision.gotoAppPermissionSetting();
				//#endif
				}
			},
			bindPickerChange:function(vl){
				this.indexarr=vl.detail.value;
				uni.setStorageSync('sound', parseInt(vl.detail.value)); //图片地址
			},
			urlfun:function(url){
				uni.navigateTo({
					url:url
				})
			},
			getupfun:function(){
				uni.setStorageSync('user','');//登陆凭证
				uni.setStorageSync('user_key','');
				uni.setStorageSync('yhpz','');
				uni.reLaunch({
				    url: '../../pages/user/user'
				});
			}
		}
	}
</script>

<style lang="scss">
.getup{
	width: 100%;
	height: 100upx;
	line-height: 100upx;
	text-align: center;
	color:$color-black-1;
	font-size: $color-size-5;
	background-color: $bgcolor-white-0;
	margin-bottom: 20upx;
}
.list{
	background-color: $bgcolor-white-0;
	width: 100%;
	height: 100upx;
	line-height: 100upx;
	display: flex;
	justify-content: center;
	border-bottom: 1px solid $bkcolor-black-9;
	.list_name{
		padding-left: 10upx;
		width: 330upx;
		color:$color-black-1;
		font-size: $color-size-5;
	}
	.list_value{
		padding-left: 10upx;
		width: 300upx;
		color:$color-black-5;
		font-size: $color-size-5;
		text-align: right;
	}
	.list_icon{
		padding-right: 10upx;
		width: 100upx;
		color:$color-black-5;
		font-size: $color-sizeicon-4;
		font-family: iconfont;
		text-align: right;
		display: flex;
		align-items: center;
		justify-content: flex-end;
	}
}
</style>
